﻿using PBO.Data.Domain;
using PBO.Data.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace PBO.Data.SQLite.DAL
{
    public class DALItemData : DALModel<ItemData>
    {

        #region Instance

        private DALItemData() { }

        private static DALItemData instance;

        public static DALItemData GetInstance()
        {
            if (instance == null)
                instance = new DALItemData();
            return instance;
        }

        #endregion

        #region tool

        public ItemData GetByPOId(int id)
        {
            return base.GetModel("poid=" + id).FirstOrDefault();
        }

        public ItemData GetByBWPBOId(int id)
        {
            return base.GetModel("newid=" + id).FirstOrDefault();
        }

        public DataTable GetAllName()
        {
            string sql = "select itemid,name from pbo_item";
            return DBUtility.ExecuteDataTable(sql);
        }

        #endregion

        #region override

        protected override string GetTableName()
        {
            return "pbo_item";
        }

        protected override ItemData DataRowToModel(DataRow dr)
        {
            var data = new ItemData();
            data.Id = dr["itemid"].ToString().ToInt();
            data.POId = dr["poid"].ToString().ToInt();
            data.BWPBOId = dr["newid"].ToString().ToInt();
            data.Name = dr["name"].ToString();
            return data;
        }

        public ItemData GetModel(int id)
        {
            return base.GetModel("itemid=" + id).FirstOrDefault();
        }

        #endregion

    }
}
